package logger

import (
	"io"
	"log"
	"os"
	"path/filepath"
)

var (
	Info    *log.Logger
	Warning *log.Logger
	Error   *log.Logger
)

func init() {
	currentWorkDIR, _ := os.Getwd()

	println(currentWorkDIR)
	println(filepath.Join(currentWorkDIR, "info.log"))

	infoFile, _ := os.OpenFile(filepath.Join(currentWorkDIR, "logger/log_data/info.log"), os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
	warnFile, _ := os.OpenFile(filepath.Join(currentWorkDIR, "logger/log_data/warn.log"), os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
	errFile, _ := os.OpenFile(filepath.Join(currentWorkDIR, "logger/log_data/errors.log"), os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)

	Info = log.New(os.Stdout, "Info:", log.Ldate|log.Ltime|log.Lshortfile)
	Warning = log.New(os.Stdout, "Warning:", log.Ldate|log.Ltime|log.Lshortfile)
	Error = log.New(io.MultiWriter(os.Stderr, errFile), "Error:", log.Ldate|log.Ltime|log.Lshortfile)

	Info = log.New(io.MultiWriter(os.Stderr, infoFile), "Info:", log.Ldate|log.Ltime|log.Lshortfile)
	Warning = log.New(io.MultiWriter(os.Stderr, warnFile), "Warning:", log.Ldate|log.Ltime|log.Lshortfile)
	Error = log.New(io.MultiWriter(os.Stderr, errFile), "Error:", log.Ldate|log.Ltime|log.Lshortfile)
}

func handlerError(args ...interface{}) {
	Error.Println(args...)
}
